
# class IndexError(Exception):
#     def __init__(self,ErrorInfo):
#         super().__init__(self) #初始化父类
#         self.errorinfo=ErrorInfo
#     def __str__(self):
#         return self.errorinfo


class CirQueue(object):
	# len函数返回可能有问题
	a,front,rear,s,size=0,0,0,0,0
	def __init__(self,size):
		self.a={}
		self.size=size
		self.front,self.rear,self.s=0,0,0
	def getin(self,date):
		if self.s==1 \
		and self.front==self.rear:
			raise IndexError('OverFlow')
		else:
			self.rear=(self.rear+1)%self.size
			self.a[self.rear]=date
			self.s=1
			return True
	def getout(self):
		if self.s==0:
			raise IndexError('UnderFlow')
		else:
			self.front=(self.front+1)%self.size
			if self.front==self.rear:
				self.s=0
			return self.a.get(self.front)
	def getfront(self):
		if self.s ==0:
			raise IndexError('UnderFlow')
		else:
			return self.a.get(self.front)
	def getrear(self):
		if self.s==0:
			raise IndexError('UnderFlow')
		else:
			return self.a.get(self.rear)
	def getsize(self):
		return self.size
	def getstate(self):
		if self.s==0:
			return False
		else:
			return True
	def __len__(self):
		if self.front == self.rear:
			return 0
		if self.rear < (self.front+1)%self.size:
			return self.size-self.front+self.rear
		else:
			return self.rear-self.front+1


class Stack(object):
	a,top=0,0
	
	def __init__(self):
		self.a={}
		self.top=0
		
	def getin(self,date):
		self.top=self.top+1
		self.a[self.top]=date
		return True
	def getout(self):
		if self.top==0:
			raise IndexError('UnderFlow')
		else:
			self.top=self.top-1
			return self.a.get(self.top+1)
	def getsize(self):
		return self.top
	def getstate(self):
		if self.top==0:
			return False
		else:
			return True
	def gettop(self):
		if self.top==0:
			raise IndexError('UnderFlow')
		else:
			return self.a.get(self.top)
	
	def getbottom(self):
		if self.top==0:
			raise IndexError('UnderFlow')
		else:
			return self.a.get(0)
			
